package com.cgx.tablet.beeper.utils;

import android.content.Context;
import android.support.annotation.StringRes;
import android.widget.Toast;

/**
 * Toast工具类
 * Created by Droven on 2017/7/16.
 */

public class ToastUtil {

    private static Toast mToast;

    /**
     * 取消上一个Toast，再显示下一个Toast
     *
     * @param context  context
     * @param msg      消息
     * @param duration Toast时长标签
     */
    private static void show(Context context, String msg, int duration) {
        if (mToast != null)
            mToast.cancel();
        mToast = Toast.makeText(context, msg, duration);
        mToast.show();
    }

    public static void showShort(Context context, @StringRes int resId) {
        show(context, context.getResources().getString(resId), Toast.LENGTH_SHORT);
    }

    public static void showShort(Context context, String msg) {
        show(context, msg, Toast.LENGTH_SHORT);
    }

    public static void showLong(Context context, @StringRes int resId) {
        show(context, context.getResources().getString(resId), Toast.LENGTH_LONG);
    }

    public static void showLong(Context context, String msg) {
        show(context, msg, Toast.LENGTH_LONG);
    }

    public static void cancel() {
        if (mToast != null)
            mToast.cancel();
    }

}
